import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/login',
    name:'login',
    component:()=>import('@/views/login.vue')
  },
  {
    path:'/register',
    name:'register',
    component:()=>import('@/views/register.vue'),
    beforeEnter:(to,from,next)=>{
      if (from.name==='login') {
        next()
      }else{
        next('/login')
      }
    }
  },
  {
    path:'/forget',
    name:'forget',
    component:()=>import('@/views/forget.vue')
  },
  {
    path:'/socket',
    name:'socket',
    component:()=>import('@/views/socket.vue')
  },
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/Order',
    name: 'Order',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Order.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
